package cn.aiweiyi.qingjing.coupon.comm.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 优惠券分类枚举
 */
@Getter
@AllArgsConstructor
public enum CouponCategory {
    MANJIAN("满减券", "001"),
    LIJIAN("立减券", "002"),
    ZHEKOU("折扣券", "003"),
    MANJIAN_ZHEKOU("满减价折扣", "004");

    //优惠券分类说明
    private String desc;

    //优惠券分类编码
    private String code;

    //提供一个方便的方法,用于根据字符串code转换枚举类型
    public static CouponCategory of(String code) {
        //要求该参数不为空
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(couponCategory -> couponCategory.code.equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(
                        code + "优惠券分类不存在"));
    }
}
